package edu.ncst.baseweb.controller.equ;

import cn.wintersun.basecommon.common.Result;
import edu.ncst.baseweb.dao.equ.EquClass;
import edu.ncst.baseweb.service.intrer.equ.EquClassService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * 设备类控制器
 * 设备种类管理
 */
@RestController
@RequestMapping("admin/equipment/equclass")
@PreAuthorize("hasAuthority('3')")
public class EquClassController {
    @Autowired
    private EquClassService equClassService;
    //设备类型列表
    @RequestMapping(value = "list",method = RequestMethod.POST)
    public Result<IPage<EquClass>> list(@RequestBody EquClass equClass){

        return  equClassService.list(equClass);
    }
    //新增or修改
    @RequestMapping(value = "save",method = RequestMethod.POST)
    public Result<Object> save(@RequestBody EquClass equclass){
        try {
            return  equClassService.save(equclass);
        } catch (Exception e) {
            //抛出异常
            return Result.failure(500, e.getMessage());
        }
    }

    //刪除
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public Result<Object> delete(@RequestBody String classId){
        try {
            return equClassService.delete(classId);
        } catch (Exception e) {
            return Result.failure(500, e.getMessage());
        }
    }
    //詳情

}
